
<?php

class MyController extends Controller
{
	public function actionIndex()
	{
		echo "<div id='output'>";
		$a=Kazakh::model()->count();
		$r=rand(1, $a);
		$b=Kazakh::model()->findByPk($r);
		 echo $b->word;
		 echo "</br>";
		$all=Russian::model()->findAllByAttributes(array('id_kaz'=>array($r)));
		foreach($all as $one)
		{
			
			echo $one->word;
			echo '  ';
			echo $one->freq;
			echo '  ';
			echo CHtml::link('golosovat',array('my/add','param1'=>$one->id,'param2'=>$one->freq, 'json'=>false));
			echo '</br>';
echo CHtml::ajaxLink(
  "Link Text",
  Yii::app()->createUrl( 'my/add' ),
  array( // ajaxOptions
    'type' => 'POST',
    'beforeSend' => "function( request )
                     {
                       // Set up any pre-sending stuff like initializing progress indicators
                     }",
    'success' => "function( data )
                  {
                    // handle return data
                    alert( data );
                  }",
    'data' => array( 'param1'=>$one->id,'param2'=>$one->freq, 'json'=>false )
  )
);
			echo '<br />';
		}
		echo "</div>";
		if(!Yii::app()->request->isAjaxRequest){
   			echo "noooo";
   			Yii::app()->end();
		}
		else
		{
			echo 'eye';
		}
	}
	public function actionAdd(){
		echo "string";
		
	$id = $_REQUEST['param1'];
	$freq = $_REQUEST['param2'];
	$freq++;
Russian::model()->updateByPk($id, array(
    'freq' => $freq
));
	if($_GET['json'])
	{
	echo json_encode($_GET);
}
//$this->redirect(array('my/index')); 
if(Yii::app()->request->isAjaxRequest){
   //echo json_encode(array('redirect'=>$this->createUrl('my/index')));
	echo 'noooo';
}
 /*if (!isset($_GET['ajax']))
                $this->redirect(Yii::app()->createUrl('my/index'));
	*/}



public function actionFunction() {
//$s=Yii::app()->request->getPost();
 if(Yii::app()->request->isAjaxRequest){

	echo "yep";
  Yii::app()->end();

 

 }

}





}